package com.fzf.org.toolkit;

import jakarta.annotation.PostConstruct;
import lombok.RequiredArgsConstructor;
import org.redisson.api.RBloomFilter;
import org.redisson.api.RedissonClient;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class RedisBloomFilterService {

    private final RedissonClient redissonClient;
    private RBloomFilter<String> accountFilter;

    @PostConstruct
    public void init() {
        this.accountFilter = redissonClient.getBloomFilter("account:bloom");
        this.accountFilter.tryInit(1000000L, 0.01); // 初始化：预计100w用户，误判率1%
    }

    public void addAccount(String account) {
        accountFilter.add(account);
    }

    public boolean containsAccount(String account) {
        return accountFilter.contains(account);
    }
}
